home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / examples / irisgl_vs_opengl / depthcue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  3.1 KB  |  139 lines

  1. /*
  2.  * Copyright 1993, 1996, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /* depthcue.c - demonstrates using fog for depth cueing 
  19.  *
  20.  *    Escape key    - exit the program
  21.  */
  22. #include <GL/gl.h>
  23. #include <GL/glu.h>
  24. #include <GL/glut.h>
  25.  
  26. #include <math.h>
  27. #include <stdio.h>
  28.  
  29. /* Function Prototypes */
  30.  
  31. GLvoid  initgfx( GLvoid );
  32. GLvoid  drawScene( GLvoid );
  33. GLvoid  reshape( GLsizei, GLsizei );
  34. GLvoid  keyboard( GLubyte, GLint, GLint );
  35.  
  36. void printHelp( char * );
  37.  
  38. /* Global Definitions */
  39.  
  40. #define KEY_ESC    27    /* ascii value for the escape key */
  41.  
  42. /* Global Variables */
  43.  
  44. void
  45. main( int argc, char *argv[] )
  46. {
  47.     GLsizei     width, height;
  48.  
  49.     glutInit( &argc, argv );
  50.  
  51.     width = glutGet( GLUT_SCREEN_WIDTH ); 
  52.     height = glutGet( GLUT_SCREEN_HEIGHT );
  53.     glutInitWindowPosition( width/4, height/4 ); 
  54.     glutInitWindowSize( width/2, height/2 );
  55.     glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
  56.     glutCreateWindow( argv[0] );
  57.     
  58.     initgfx();
  59.  
  60.     glutKeyboardFunc( keyboard );
  61.     glutReshapeFunc( reshape );
  62.     glutDisplayFunc( drawScene ); 
  63.  
  64.     printHelp( argv[0] );
  65.  
  66.     glutMainLoop();
  67. }
  68.  
  69. GLvoid
  70. printHelp( char *progname )
  71. {
  72.     fprintf(stdout,
  73.         "\n%s - demonstrates how to use fog for depth cueing\n\n"\
  74.         "Escape key        - exit the program\n\n",
  75.         progname
  76.     );
  77. }
  78.  
  79. /* Initialize enable depth buffer, and set initial fog parameters  */
  80.  
  81. GLvoid
  82. initgfx( GLvoid )
  83. {
  84.     GLfloat     fogColor[4] = { 0.0, 0.0, 0.0, 1.0 };
  85.  
  86.     glEnable( GL_DEPTH_TEST );
  87.  
  88.     glFogi( GL_FOG_MODE, GL_LINEAR );
  89.     glHint( GL_FOG_HINT, GL_NICEST );  /*  per pixel   */
  90.     glFogf( GL_FOG_START, 3.0 );
  91.     glFogf( GL_FOG_END, 5.0 );
  92.  
  93.     glFogfv( GL_FOG_COLOR, fogColor );
  94.  
  95.     glEnable( GL_FOG );
  96.  
  97.     /* clear background to the same color as the fog */
  98.     glClearColor( fogColor[0], fogColor[1], fogColor[2], fogColor[3] );
  99. }
  100.  
  101. GLvoid 
  102. keyboard( GLubyte key, GLint x, GLint y )
  103. {
  104.     switch (key) {
  105.     case KEY_ESC:    /* Exit whenever the Escape key is pressed */
  106.         exit(0);
  107.     }
  108. }
  109.  
  110. GLvoid
  111. reshape( GLsizei width, GLsizei height )
  112. {
  113.     GLdouble    aspect;
  114.  
  115.     glViewport( 0, 0, width, height );
  116.  
  117.     aspect = (GLdouble) width / (GLdouble) height;
  118.  
  119.     glMatrixMode( GL_PROJECTION );
  120.     glLoadIdentity();
  121.     gluPerspective( 45.0, aspect, 3.0, 5.0 );
  122.     glMatrixMode( GL_MODELVIEW );
  123.     glLoadIdentity();
  124.     glTranslatef( 0.0, 0.0, -4.0 );  /*  move object into view   */
  125. }
  126.  
  127. GLvoid
  128. drawScene( GLvoid )
  129. {
  130.     int i,  slices = 8;
  131.     
  132.     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  133.     
  134.     glColor3f( 1.0, 1.0, 1.0 );
  135.     glutWireIcosahedron();
  136.  
  137.     glutSwapBuffers();
  138. }
  139.